
import HTTP from '../util/http.js';

export default class KeywordModel extends HTTP {
    key = 'q';
    maxLength = 10;
    getHistory(){
        const words = wx.getStorageSync(this.key);
        if (!words){
            return [];
        }
        return words;
    }
    getHot(){
        return this.request({
            url: '/book/hot_keyword'
        });
    }
    addToHistory(keyword){
        let words = this.getHistory();
        let hasWord = words.includes(keyword);
        if (!hasWord){
            let len = words.length;
            if (len >= this.maxLength){
                words.pop();
            }
            words.unshift(keyword);
            wx.setStorageSync(this.key, words);
        }
    }
    searchBook(start, summary, q){
        return this.request({
            url: '/book/search',
            data: {
                start: start,
                summary: summary,   //0为完整内容,1为简介
                q: q
            }
        });
    }       
}



















